package com.njsf.controller.front;

import com.njsf.annotation.Token;
import com.njsf.dto.ResponseJson;
import com.njsf.pojo.Cart;
import com.njsf.pojo.CartPlus;
import com.njsf.pojo.User;
import com.njsf.service.CartService;
import com.njsf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

<<<<<<< HEAD
import javax.servlet.ServletException;
=======
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/front")
public class CartFrontController {

    @Autowired
    private CartService cartService;

    @Autowired
    private OrderService orderService;

    @RequestMapping("/addcart")
    @ResponseBody
<<<<<<< HEAD
    public ResponseJson addCart(Cart cart) throws Exception{
=======
    public ResponseJson addCart(Cart cart){
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
       return cartService.addCart(cart);
    }

    @RequestMapping("/cartview")
    @Token(create = true)
<<<<<<< HEAD
    public String cartView(HttpSession session, Map<String,Object> map) throws Exception{
        User user = (User) session.getAttribute("user");
        List<CartPlus> carts = cartService.findAllByUser(user.getId());
        map.put("carts",carts);
        int a =1/0;
=======
    public String cartView(HttpSession session, Map<String,Object> map){
        User user = (User) session.getAttribute("user");
        List<CartPlus> carts = cartService.findAllByUser(user.getId());
        map.put("carts",carts);
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
        return "front/cart";
    }

    /**产生订单
     * @param cartPluses
     */
    @RequestMapping("/cartaccout")
    @ResponseBody
    @Token(remove = true)
<<<<<<< HEAD
    public ResponseJson cartAccout(@RequestBody List<CartPlus> cartPluses,HttpSession session) throws Exception{
        Integer userId = ((User)session.getAttribute("user")).getId();
        return orderService.createOrder(cartPluses,userId);
    }
=======
    public ResponseJson cartAccout(@RequestBody List<CartPlus> cartPluses,HttpSession session){
        Integer userId = ((User)session.getAttribute("user")).getId();
        return orderService.createOrder(cartPluses,userId);
    }






>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
}
